package com.sys.basics.controller;

import com.sys.basics.config.annotation.SysLogAnnotation;
import com.sys.basics.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import com.sys.basics.config.jsonRes.JsonResult;
import com.sys.basics.config.jsonRes.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sys.basics.entity.SysDict;
import com.sys.basics.service.SysDictService;
import io.swagger.annotations.*;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;

/**
 * @author: ares
 * @date: 2021-10-08
 * @description: 字典表 前端控制器
 */
@Validated
@Slf4j
@Api(tags = "字典管理")
@RestController
@RequestMapping("/basics/sysDict")
public class SysDictController extends AbstractController<SysDictService, SysDict> {

    private JsonResult<List<SysDict>> listResult = new JsonResult<>();

    @Autowired
    SysDictService sysDictService;

    /**
     * @param type
     * @return JsonResult<SysDict>
     * @author: ares
     * @date: 2021-10-08 10:22:24
     * @description:
     */
    @SysLogAnnotation("获取某组织类型的下级组织类型")
    @ApiOperation("获取某组织类型的下级组织类型")
    @ApiImplicitParam(name = "orgTypeK", value = "组织类型k值", paramType = "query")
    @GetMapping("/getChildrenOrgType")
    public JsonResult<List<SysDict>> getChildrenOrgType(@NotEmpty(message = "组织类型k值不能为空") String orgTypeK) {
        return listResult.success(sysDictService.getChildrenOrgType(orgTypeK));
    }

    @SysLogAnnotation("根据类型查询字典")
    @ApiOperation("根据类型查询字典")
    @ApiImplicitParam(name = "type", value = "字典类型", paramType = "query")
    @GetMapping("/getByType")
    public JsonResult<List<SysDict>> getByType(@NotEmpty(message = "类型不能为空") String type) {
        return listResult.success(sysDictService.getByType(type));
    }

    /**
     * @param types
     * @return JsonResult<List<SysDict>>
     * @author: ares
     * @date: 2021-10-08 10:22:24
     * @description:
     */
    @SysLogAnnotation("根据多个类型查询字典")
    @ApiOperation("根据多个类型查询字典")
    @PostMapping("/getByTypes")
    public JsonResult<List<SysDict>> getByTypes(@RequestBody @NotEmpty List<String> types) {
        return listResult.success(sysDictService.getByTypes(types));
    }

}
